#include <iostream>
using namespace std;
#include <vector>

class Solution
{
public:
    static string longestPalindrome(const string& s)
    {
        int begin = 0, len = 0;
        for(int i=0; i<s.size(); i++)
        {
            int left = i, right = i;
            while(left >=0 && right <= s.size() && s[left] == s[right])
            {
                left--;
                right++;
            }
            if(right-left-1 > len)
            {
                begin = left+1;
                len = right-left-1;
            }

            left = i, right = i+1;
            while(left >=0 && right <= s.size() && s[left] == s[right])
            {
                left--;
                right++;
            }
            if(right-left-1 > len)
            {
                begin = left+1;
                len = right-left-1;
            }
        }
        return s.substr(begin, len);
    }
};
